package com.hl.controller;

import com.hl.domain.*;
import com.hl.service.CourseDetailService;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/courseDetail")

public class CourseDetailController {
    @Autowired
    private CourseDetailService courseDetailService;

    //展示课程详情数据
    @GetMapping("/xiangqing")
    public R courseDetail(Long id){
        Course course = courseDetailService.courseDetail(id);
        return R.success(course);
    }


    @GetMapping("/courseList")
    public R videoList(Long courseId, @RequestParam(defaultValue = "1") Long userId) {
        System.out.println("courseId"+courseId);
        Map map = courseDetailService.videoList(userId, courseId);
        //1  已经购买  0 未购买
        return R.success(map);
    }

    //生成订单记录
    @PostMapping("/createOrder")
    public R createOrder(Order order) {
        int i = courseDetailService.createOrder(order);
        return R.success(i);
    }


    //查询课程下的名师介绍
    @GetMapping("/teacherInfo")
    public R queryTeacherIntro(Integer courseId){
        TeacherInfoDTO teacherInfoDTO = courseDetailService.queryTeacherIntro(courseId);
        System.out.println("------------");
        System.out.println(teacherInfoDTO);
        return R.success(teacherInfoDTO);
    }


    //查询该课程的所有评价
    @GetMapping("/queryAllMark")
    public R queryAllMark(Long courseId){
        List<Coursemark> coursemarks = courseDetailService.queryAllMark(courseId);
        return R.success(coursemarks);
    }


    //交流回复
    @GetMapping("/getCourseQuestions")
    public R getCourseQuestions(Integer courseId) {
        List<CourseQuestion> courseQuestions = courseDetailService.getCourseQuestions(courseId);
        return R.success(courseQuestions);
    }
}
